package cn.ze.yygh.msm.service.impl;

import cn.ze.yygh.msm.service.MsmService;
import cn.ze.yygh.vo.msm.MsmVo;
import org.apache.poi.util.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

@Service
public class MsmServiceImpl implements MsmService {

    //发送验证码
    @Override
    public boolean send(String phone, String code) {
        //判断手机号是否为空
        if (StringUtils.isEmpty(phone)) return false;


        //TODO 整合阿里云服务 设置相关参数
       /* DefaultProfile profile = DefaultProfile.
                getProfile(ConstantPropertiesUtils.REGION_Id,
                        ConstantPropertiesUtils.ACCESS_KEY_ID,
                        ConstantPropertiesUtils.SECRECT);
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        //request.setProtocol(ProtocolType.HTTPS);
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");

        //手机号
        request.putQueryParameter("PhoneNumbers", phone);
        //签名名称
        request.putQueryParameter("SignName", "我的谷粒在线教育网站");
        //模板code
        request.putQueryParameter("TemplateCode", "SMS_180051135");
        //验证码  使用json格式   {"code":"123456"}
        Map<String,Object> param = new HashMap();
        param.put("code",code);
        request.putQueryParameter("TemplateParam", JSONObject.toJSONString(param));
        */

        return true;

    }

    // mq 发送短信的封装
    @Override
    public boolean send(MsmVo msmVo) {
        //判断手机号是否为空
        if (StringUtils.isEmpty(msmVo.getPhone())) return false;

        String code = (String) msmVo.getParam().get("code");
        boolean isSend = this.send(msmVo.getPhone(), code);


        return isSend;
    }



    private boolean send(String phone, Map<String,Object> map) {
        //判断手机号是否为空
        if (StringUtils.isEmpty(phone)) return false;

        System.out.println(map);

        return true;

    }
}
